﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using secondhand.L2busslogic;
using secondhand.L1database;
using secondhand.L3object;
using System.IO;

namespace secondhand.L4view.yonghu
{
    public partial class yognhu_pay : System.Web.UI.Page
    {
        public static string bookname;
        public static string salerName;
        public static string Url;
        public static string booktype;
        public static string bookdescribe;

        protected void Page_Load(object sender, EventArgs e)
        {
            goodsOB mydd = new goodsOB();
            mydd = goodsBL.Getwordsingle((Session["goods_Name1"].ToString()));
            Label6.Text = DateTime.Now.ToString();
            Label7.Text = Session["login"].ToString();
            Label8.Text = mydd.saler_name;
            Session["saler_nam"] = mydd.saler_name;//出售者名字
            Label9.Text = mydd.goods_price;
            bookname = mydd.goods_name;
            booktype = mydd.goods_type;
            Url = mydd.goods_picture;
            bookdescribe = mydd.goods_describe;
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            bookOB myword = new bookOB();
            myword.saler_name = Label8.Text;
            myword.book_name = bookname;
            myword.book_type = booktype;
            myword.book_price = Label9.Text;
            myword.book_time = DateTime.Now.ToString();
            myword.book_picture = Url;
            myword.book_describe = bookdescribe;
            myword.user_name = Session["login"].ToString();
            myword.receive_goods = "0";
            userOB mydd = new userOB();
            mydd = userBL.Getwordsingle((Session["login"].ToString()));
            int count2 = (int)Convert.ToSingle(myword.book_price);
            int count = (int)Convert.ToSingle(mydd.user_count) - count2;
            if (count < 0)
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('账上余额不足，请充值!');{location.href='yonghu_recharge.aspx'}</script>");
                return;
            }
            mydd.usable_count = count.ToString();
            mydd.freeze_count = count2.ToString();
            if (bookBL.Addfill(myword))
            {
                if (userBL.Savemark(mydd))
                { 
                    
                }
                goodsBL.deleteword(myword.book_name);
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('支付成功，等待收货!');{location.href='yonghu_person_info.aspx'}</script>");
                return;
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('支付不成功!');{location.href='yonghu_search.aspx'}</script>");
                return;
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/L4View/yonghu/yonghu_person_info.aspx");
        }
    }
}